const formatTag = function(value) {
    if (value.indexOf(" ")) {
        var temp = ''
        value = value.split(" ");
        for (var i = 0; i < value.length; i++) {
            temp = temp + value[i] + '_'
        }
        value = temp.slice(0, temp.length - 1)
    }
    return value;
}
const getRealUrl = function(disDocData, requestData) {
    let url = disDocData.path
    if (typeof(disDocData) === 'undefined' || typeof(disDocData.parameters) === 'undefined') {
        return url
    }
    disDocData.parameters.forEach(function(param) {
        if (param.in === 'path') {
            if (typeof(requestData[param.in][param.name]) !== 'undefined') {
                url = url.replace('{' + param.name + '}', requestData[param.in][param.name])
            }
        }
    })
    return url
}
const getQuery = function(data) {
    let queryString = '?'
    for (let query in data['query']) {
        queryString += query + '=' + data['query'][query] + '&'
    }
    return encodeURI(queryString.slice(0, queryString.length - 1))
}
const getForm = function(data) {
    return data.formData
}
const getChildrenList = function(current, all) {
    var list = [];
    var i = 0;
    //console.log(current)
    for (let path in all) {
        for (let method in all[path]) {
            all[path][method].tags.forEach(function(tag) {
                //console.log(tag, current)
                if (tag === current) {
                    all[path][method]['path'] = path
                    all[path][method]['method'] = method
                    list[i++] = all[path][method]
                }
            });
        }
    }
    return list
}
const getFirstChild = function(current, all) {
    return getChildrenList(current, all)[0]
}
export default {
    formatTag,
    getForm,
    getQuery,
    getRealUrl,
    getChildrenList,
    getFirstChild
}